#include "lolevel.h"
#include "platform.h"
#include "core.h"

const char * const new_sa = &_end;


extern long wrs_kernel_bss_start;
extern long wrs_kernel_bss_end;




void CreateTask_PhySw();
void CreateTask_spytask();

void boot();



#define DEBUG_LED 0xC02200C8
void boot() { 
    long *canon_data_src = (void*)0xFFAFB86C;
    long *canon_data_dst = (void*)0x1900;
    long canon_data_len = 0x137A8 - 0x1900; 
    long *canon_bss_start = (void*)0x137A8; 
    long canon_bss_len = 0xA6234 - 0x137A8; 

    long i;


    
    asm volatile (
	"MRC     p15, 0, R0,c1,c0\n"
	"ORR     R0, R0, #0x1000\n"
	"ORR     R0, R0, #4\n"
	"ORR     R0, R0, #1\n"
	"MCR     p15, 0, R0,c1,c0\n"
    :::"r0");

    for(i=0;i<canon_data_len/4;i++)
	canon_data_dst[i]=canon_data_src[i];

    for(i=0;i<canon_bss_len/4;i++)
	canon_bss_start[i]=0;


    
    asm volatile ("B      sub_FF8101a4_my\n");
}; 



void __attribute__((naked,noinline)) sub_FF8101a4_my() { 
        asm volatile (
		"LDR	R0, =0xFF81021C\n"
		"MOV	R1, #0\n"
		"LDR	R3, =0xFF810254\n"

        "loc_FF8101B0:\n"
		"CMP	R0, R3\n"
		"LDRCC	R2, [R0],#4\n"
		"STRCC	R2, [R1],#4\n"
		"BCC	loc_FF8101B0\n"
		"LDR	R0, =0xFF810254\n"
		"MOV	R1, #0x4B0\n"
		"LDR	R3, =0xFF810468\n"

        "loc_FF8101CC:\n"
		"CMP	R0, R3\n"
		"LDRCC	R2, [R0],#4\n"
		"STRCC	R2, [R1],#4\n"
		"BCC	loc_FF8101CC\n"
		"MOV	R0, #0xD2\n"
		"MSR	CPSR_cxsf, R0\n"
		"MOV	SP, #0x1000\n"
		"MOV	R0, #0xD3\n"
		"MSR	CPSR_cxsf, R0\n"
		"MOV	SP, #0x1000\n"
		"LDR	R0, =0x6C4\n"
		"LDR	R2, =0xEEEEEEEE\n"
		"MOV	R3, #0x1000\n"

        "loc_FF810200:\n"
		"CMP	R0, R3\n"
		"STRCC	R2, [R0],#4\n"
		"BCC	loc_FF810200\n"
		
                "BL      sub_FF810FB8_my\n"
        );

} 

void __attribute__((naked,noinline)) sub_FF810FB8_my() { 
        asm volatile (
        	"STR	LR, [SP,#-4]!\n"            
		"SUB	SP, SP,	#0x74\n"
		"MOV	R0, SP\n"
		"MOV	R1, #0x74\n"
		"BL	sub_FFA91C1C\n"
		"MOV	R0, #0x53000\n"
		"STR	R0, [SP,#0x74-0x70]\n"
        );

        asm volatile (
                "LDR    R0, =new_sa\n"
                "LDR    R0, [R0]\n"
        );
        asm volatile (
		"LDR	R2, =0x2ABC00\n"
		"LDR	R1, =0x2A4968\n"
		"STR	R0, [SP,#0x74-0x6C]\n"
		"SUB	R0, R1,	R0\n"
		"ADD	R3, SP,	#0x74-0x68\n"
		"STR	R2, [SP,#0x74-0x74]\n"
		"STMIA	R3, {R0-R2}\n"
		"MOV	R0, #0x22\n"
		"STR	R0, [SP,#0x74-0x5C]\n"
		"MOV	R0, #0x68\n"
		"STR	R0, [SP,#0x74-0x58]\n"
		"LDR	R0, =0x19B\n"
		"MOV	R1, #0x64\n"
                
                "STR    R0, [SP,#0x74-0x54]\n"          
                "STR    R1, [SP,#0x74-0x50]\n"

                "MOV    R0, #0x78\n"
                
                "STR    R0, [SP,#0x74-0x4C]\n"          
                "STR    R1, [SP,#0x74-0x48]\n"

		"MOV	R0, #0\n"
		"STR	R0, [SP,#0x74-0x44]\n"
		"STR	R0, [SP,#0x74-0x40]\n"
		"MOV	R0, #0x10\n"
		"STR	R0, [SP,#0x74-0x18]\n"
		"MOV	R0, #0x800\n"
		"STR	R0, [SP,#0x74-0x14]\n"
		"MOV	R0, #0xA0\n"
		"STR	R0, [SP,#0x74-0x10]\n"
		"MOV	R0, #0x280\n"
		"STR	R0, [SP,#0x74-0x0C]\n"

	
                "LDR    R1, =uHwSetup_my\n"          
		
                "MOV	R0, SP\n"
		"MOV	R2, #0\n"
		"BL	sub_FF812D70\n"
		"ADD	SP, SP,	#0x74\n"
		"LDR	PC, [SP],#4\n"
        );
}; 

void __attribute__((naked,noinline)) uHwSetup_my() { 
        asm volatile (
        	"STMFD	SP!, {R4,LR}\n"
		"BL	sub_FF81095C\n"
		"BL	sub_FF819948\n"
		"CMP	R0, #0\n"
		"LDRLT	R0, =0xFF814ED0\n"
		"BLLT	sub_FF814EB0\n"
		"BL	sub_FF8149E0\n"
		"CMP	R0, #0\n"
		"LDRLT	R0, =0xFF814ED8\n"
		"BLLT	sub_FF814EB0\n"
		"LDR	R0, =0xFF814EE8\n"
		"BL	sub_FF814ACC\n"
		"CMP	R0, #0\n"
		"LDRLT	R0, =0xFF814EF0\n"
		"BLLT	sub_FF814EB0\n"
		"LDR	R0, =0xFF814EE8\n"
		"BL	sub_FF81357C\n"
		"CMP	R0, #0\n"
		"LDRLT	R0, =0xFF814F04\n"
		"BLLT	sub_FF814EB0\n"
		"BL	sub_FF8194D0\n"	
		"CMP	R0, #0\n"
		"LDRLT	R0, =0xFF814F10\n"
		"BLLT	sub_FF814EB0\n"
		"BL	sub_FF8114D0\n"
		"CMP	R0, #0\n"
		"LDRLT	R0, =0xFF814F1C\n"
		"BLLT	sub_FF814EB0\n"
		"LDMFD	SP!, {R4,LR}\n"
        
		"B	taskcreate_Startup_my\n"
        );
}; 

void __attribute__((naked,noinline)) taskcreate_Startup_my() { 
        asm volatile (
		"STMFD	SP!, {R3,LR}	\n"
		"BL	sub_FF822DA4	\n"
		"BL	sub_FF82BA24	\n"
		"CMP	R0, #0		\n"
		"BNE	loc_FF81DC44	\n"
		"LDR	R2, =0xC0220000	\n"
		"LDR	R0, [R2,#0x7C]	\n"
		"LDR	R1, [R2,#0x78]	\n"
		"AND	R0, R0,	R1	\n"
		"TST	R0, #1		\n"
		"BEQ	loc_FF81DC44	\n"
		"MOV	R0, #0x44	\n"
		"STR	R0, [R2,#0x4C]	\n"

        "loc_FF81DC40:\n"
		"B	loc_FF81DC40	\n"

        "loc_FF81DC44:\n"
		"BL	sub_FF822DAC	\n"
		"BL	sub_FF822DA8	\n"
		"BL	sub_FF8295B0	\n"
		"MOV	R1, #0x300000	\n"
		"MOV	R0, #0		\n"
		"BL	sub_FF8297F8	\n"
		"BL	sub_FF8297A4	\n"
		"MOV	R3, #0		\n"
		"STR	R3, [SP,#8-8]   \n"

        
                "LDR    R3, =task_Startup_my\n"      

                "MOV	R2, #0		\n"
		"MOV	R1, #0x19	\n"
		"LDR	R0, =0xFF81DC88	\n"
		"BL	sub_FF81BAF0	\n"
		"MOV	R0, #0		\n"
		"LDMFD	SP!, {R12,PC}	\n"
        );
}; 

void __attribute__((naked,noinline)) task_Startup_my() { 
        asm volatile (
        	"STMFD	SP!, {R4,LR}	\n"
		"BL	sub_FF81517C    \n"       
		"BL	sub_FF823F44	\n"
		"BL	sub_FF820E24	\n"
		
		"BL	sub_FF82BC04	\n"
		
        );

        CreateTask_spytask();

        asm volatile (
		"BL	sub_FF82BDCC	\n"
		"BL	sub_FF82BC54	\n"
		"BL	sub_FF828AF4	\n"
		"BL	sub_FF82BDD0	\n"
        );

        CreateTask_PhySw();

        asm volatile (
		
		"BL	sub_FF825BD0_my	\n"       
		"BL	sub_FF82BDE8	\n"
		
		"BL	sub_FF8220D8	\n"
		"BL	sub_FF82B7D0	\n"       
		"BL	sub_FF822874	\n"
		"BL	sub_FF821FE4    \n"       
		"BL	sub_FF82C88C_my	\n"       

		"BL	sub_FF821FA0	\n"

                
        	"BL	sub_FF815088	\n"
		"LDMFD	SP!, {R4,PC}	\n"       


        );
}; 

void CreateTask_spytask() { 
        _CreateTask("SpyTask", 0x19, 0x2000, core_spytask, 0);

}; 

void CreateTask_PhySw() { 
        _CreateTask("PhySw", 0x18, 0x800, mykbd_task, 0);
}; 


void __attribute__((naked,noinline)) sub_FF825BD0_my() { 
        asm volatile (
                "STMFD   SP!, {R4,LR}   \n"
                "LDR     R4, =0x1CB8    \n"
                "MOV     R0, #0         \n"
                "MOV     R1, #4         \n"
                "STR     R0, [R4,#0xC]  \n"
                "BL      sub_FF81BE20   \n"
                "STR     R0, [R4,#4]    \n"
                "MOV     R0, #0         \n"
                "MOV     R1, #1         \n"
                "BL      sub_FF81BE44   \n"
                "STR     R0, [R4,#8]    \n"
                "BL      sub_FF85F1E8   \n"
                "BL      sub_FF85E190   \n"
                "BL      sub_FF85B318_my \n"         
                "BL      sub_FF85F4D0   \n"
                "LDR     R0, [R4,#4]    \n"
                "LDMFD   SP!, {R4,LR}   \n"
                "MOV     R1, #0x1000    \n"
                "B       sub_FF828E54   \n"
        );
}; 

void __attribute__((naked,noinline)) sub_FF85B318_my() { 
        asm volatile (
        	"STMFD	SP!, {R4,LR}		 \n"
		"LDR	R4, =0x55FC		 \n"
		"LDR	R0, [R4,#8]		 \n"
		"CMP	R0, #0			 \n"
		"BNE	loc_FF85B384		 \n"
		
		"MOV	R1, #1			 \n"
		"MOV	R0, #0			 \n"
		"BL	sub_FF81BE44		 \n"
		"STR	R0, [R4,#0x1C]		 \n"
		"MOV	R0, #0			 \n"
		"MOV	R1, #0			 \n"
		"BL	sub_FF81BE20		 \n"
		"STR	R0, [R4,#0x20]		 \n"
		"BL	sub_FF85B6E8		 \n"
		"BL	sub_FF85B4E8      	 \n"     
		"MOV	R0, #0			 \n"
		"STR	R0, [R4,#0x18]		 \n"
		"ADD	R0, R4,	#0x24		 \n"
		"MOV	R1, #0			 \n"
		"STR	R1, [R0],#4		 \n"
		"STR	R1, [R0]		 \n"
		"BL	sub_FF85BA00		 \n"
		"BL	sub_FF85F67C		 \n"
		"BL	sub_FF85DB1C		 \n"
		"BL	sub_FF85C2A4_my	         \n"     
		"BL	sub_FF85D5D4             \n"

        " loc_FF85B384:          		 \n"
		"MOV	R0, #1			 \n"
		"STR	R0, [R4,#8]		 \n"
		"LDMFD	SP!, {R4,PC}		 \n"
        );
}; 

void __attribute__((naked,noinline)) sub_FF85C2A4_my() { 
        asm volatile (
        	"STMFD	SP!, {R3-R5,LR}		\n"
		"LDR	R2, = 0x1DA80		\n"
		"MOV	R0, #0			\n"
		"MOV	R1, #0			\n"

        "loc_FF85C2B4:				\n"
		"ADD	R3, R2,	R0,LSL#4	\n"
		"ADD	R0, R0,	#1		\n"
		"CMP	R0, #5			\n"
		"STR	R1, [R3,#8]		\n"
		"BCC	loc_FF85C2B4		\n"
		"BL	sub_FF932954		\n"
		"BL	sub_FF93470C		\n"
		"MOV	R1, #5			\n"
		"MOV	R0, #0			\n"
		"BL	sub_FF81BDFC		\n"
		"LDR	R4, =0x5648		\n"
		"LDR	R1, =0x1001FF		\n"
		"STR	R0, [R4,#0xC]		\n"
		"MOV	R0, #0			\n"
		"BL	sub_FF81BE20		\n"
		"STR	R0, [R4,#8]		\n"
		"MOV	R3, #0			\n"
		
                "STR     R3, [SP]               \n"
	
        "LDR    R3, =task_CaptSeqTask_my\n"    
		"LDR	R0, =0xFF85C470  	\n"    
		"MOV	R2, #0x1000		\n"
		"MOV	R1, #0x17		\n"
		"BL	sub_FF81BDC8		\n"
		"LDMFD	SP!, {R3-R5,PC}		\n"
        ".ltorg\n"
        );
}; 















void __attribute__((naked,noinline)) sub_FF82C88C_my() { 
        asm volatile (
                "STMFD   SP!, {R4,LR}\n"
                "BL      sub_FF86DFAC\n"
                "BL      sub_FF847DB4\n"
                "CMP     R0, #1\n"
                "BNE     loc_FF82C8AC\n"
                "BL      sub_FF8711CC\n"
                "LDMFD   SP!, {R4,LR}\n"
                "B       sub_FF847E2C\n"
                "loc_FF82C8AC:\n"
                "BL      sub_FF870188\n"
                "LDR     R4, =0x1DD0\n"
                "LDR     R0, [R4,#4]\n"
                "CMP     R0, #0\n"
                "LDMNEFD SP!, {R4,PC}\n"
                "MOV     R1, #0\n"
                "LDR     R0, =sub_FF82C398_my\n"  
                "BL      sub_FF86AA68\n"
                "STR     R0, [R4,#4]\n"
                "LDMFD   SP!, {R4,PC}\n"
        );
}; 

void __attribute__((naked,noinline)) sub_FF82C398_my() { 
        asm volatile (
                
                "STMFD   SP!, {R3-R11,LR}\n"
                "LDR     R6, =0x1DD0\n"
                "MOV     R5, R1\n"
                "LDR     R0, [R6,#0x14]\n"
                "MOV     R4, R3\n"
                "CMP     R0, #1\n"
                "BNE     loc_FF82C3BC\n"
                "BL      sub_FF86E7D4\n"
                "B       loc_FF82C7BC\n"
        "loc_FF82C3BC:\n"
                "LDR     R12, =0x1162\n"
                "LDR     R10, =0x1005\n"
                "CMP     R5, R12\n"
                "MOV     R7, #0\n"
                "MOV     R8, #1\n"
                "BEQ     loc_FF82C7E8\n"
                "BGT     loc_FF82C510\n"
                "LDR     R12, =0x1062\n"
                "CMP     R5, R12\n"
                "BEQ     loc_FF82C884\n"
                "BGT     loc_FF82C484\n"
                "CMP     R5, R10\n"
                "BEQ     loc_FF82C814\n"
                "BGT     loc_FF82C45C\n"
                "LDR     R9, =0x9A3\n"
                "CMP     R5, R9\n"
                "ADD     R10, R9, #2\n"
                "BEQ     loc_FF82C79C\n"
                "BGT     loc_FF82C43C\n"
                "SUB     R12, R5, #0x800\n"
                "SUBS    R12, R12, #3\n"
                "BEQ     loc_FF82C694\n"
                "SUB     R12, R5, #0x800\n"
                "SUBS    R12, R12, #0x158\n"
                "BNE     loc_FF82C7D8\n"
                "TST     R4, #0x80000000\n"
                "MOVNE   R0, #1\n"
                "BNE     locret_FF82C6F8\n"
                "BL      sub_FF8784B8\n"
                "CMP     R0, #0\n"
                "BLEQ    sub_FF8289E4\n"
                "B       loc_FF82C7BC\n"
        "loc_FF82C43C:\n"
                "CMP     R5, R10\n"
                "BEQ     loc_FF82C79C\n"
                "SUB     R12, R5, #0x1000\n"
                "SUBS    R12, R12, #3\n"
                "BNE     loc_FF82C7D8\n"
                "BL      sub_FF82C2CC\n"
                "MOV     R1, R4\n"
                "B       loc_FF82C7E0\n"
        "loc_FF82C45C:\n"
                "SUB     R12, R5, #0x1000\n"
                "SUBS    R12, R12, #0x56\n"
                "SUBNE   R12, R5, #0x1000\n"
                "SUBNES  R12, R12, #0x5B\n"
                "SUBNE   R12, R5, #0x1000\n"
                "SUBNES  R12, R12, #0x5E\n"
                "SUBNE   R12, R5, #0x1000\n"
                "SUBNES  R12, R12, #0x61\n"
                "BNE     loc_FF82C7D8\n"
                "B       loc_FF82C884\n"
        "loc_FF82C484:\n"
                "LDR     R12, =0x10AD\n"
                "CMP     R5, R12\n"
                "BEQ     loc_FF82C804\n"
                "BGT     loc_FF82C4D4\n"
                "SUB     R12, R5, #0x1000\n"
                "SUBS    R12, R12, #0x63\n"
                "SUBNE   R12, R5, #0x1000\n"
                "SUBNES  R12, R12, #0x65\n"
                "BEQ     loc_FF82C884\n"
                "SUB     R12, R5, #0x1000\n"
                "LDR     R0, =0x10A3\n"
                "SUBS    R12, R12, #0xA9\n"
                "BEQ     loc_FF82C7F8\n"
                "SUB     R12, R5, #0x1000\n"
                "SUBS    R12, R12, #0xAA\n"
                "BNE     loc_FF82C7D8\n"
                "BL      sub_FF86CF90\n"
                "CMP     R0, #0\n"
                "BEQ     loc_FF82C810\n"
                "B       loc_FF82C7BC\n"
        "loc_FF82C4D4:\n"
                "SUB     R12, R5, #0x1000\n"
                "SUBS    R12, R12, #0xAE\n"
                "BEQ     loc_FF82C810\n"
                "SUB     R12, R5, #0x1000\n"
                "SUBS    R12, R12, #0xAF\n"
                "BEQ     loc_FF82C804\n"
                "SUB     R12, R5, #0x1000\n"
                "SUBS    R12, R12, #0xB0\n"
                "BEQ     loc_FF82C810\n"
                "SUB     R12, R5, #0x1000\n"
                "SUBS    R12, R12, #0xB2\n"
                "BNE     loc_FF82C7D8\n"
                "LDR     R0, =0x1008\n"
                "MOV     R1, R4\n"
                "B       loc_FF82C7E0\n"
        "loc_FF82C510:\n"
                "LDR     R11, =0x201B\n"
                "LDR     R0, =0x1DD0\n"
                "CMP     R5, R11\n"
                "LDR     R2, [R0,#0x10]!\n"
                "LDR     R1, [R0,#0x10]\n"
                "SUB     R9, R11, #0x17\n"
                "BEQ     loc_FF82C770\n"
                "BGT     loc_FF82C5A8\n"
                "LDR     R11, =0x116A\n"
                "CMP     R5, R11\n"
                "BEQ     loc_FF82C75C\n"
                "BGT     loc_FF82C56C\n"
                "SUB     R0, R5, #0x1100\n"
                "SUB     R0, R0, #0x63\n"
                "CMP     R0, #5\n"
                "ADDLS   PC, PC, R0,LSL#2\n"
                "B       loc_FF82C7D8\n"
        "loc_FF82C554:\n"
                "B       loc_FF82C794\n"
        "loc_FF82C558:\n"
                "B       loc_FF82C788\n"
        "loc_FF82C55C:\n"
                "B       loc_FF82C780\n"
        "loc_FF82C560:\n"
                "B       loc_FF82C7D8\n"
        "loc_FF82C564:\n"
                "B       loc_FF82C71C\n"
        "loc_FF82C568:\n"
                "B       loc_FF82C71C\n"
        "loc_FF82C56C:\n"
                "SUB     R12, R5, #0x2000\n"
                "SUBS    R12, R12, #2\n"
                "BEQ     loc_FF82C850\n"
                "CMP     R5, R9\n"
                "MOV     R0, R9\n"
                "BEQ     loc_FF82C85C\n"
                "SUB     R12, R5, #0x2000\n"
                "SUBS    R12, R12, #5\n"
                "BEQ     loc_FF82C850\n"
                "SUB     R12, R5, #0x2000\n"
                "SUBS    R12, R12, #0x19\n"
                "BNE     loc_FF82C7D8\n"
                "CMP     R1, #0\n"
                "BNE     loc_FF82C83C\n"
                "B       loc_FF82C7BC\n"
        "loc_FF82C5A8:\n"
                "LDR     R12, =0x3110\n"
                "CMP     R5, R12\n"
                "BEQ     loc_FF82C814\n"
                "BGT     loc_FF82C5F0\n"
                "SUB     R12, R5, #0x2000\n"
                "SUBS    R12, R12, #0x1D\n"
                "BEQ     loc_FF82C850\n"
                "LDR     R0, =0x2027\n"
                "CMP     R5, R0\n"
                "BEQ     loc_FF82C81C\n"
                "SUB     R12, R5, #0x3000\n"
                "SUBS    R12, R12, #6\n"
                "BEQ     loc_FF82C814\n"
                "SUB     R12, R5, #0x3000\n"
                "SUBS    R12, R12, #0x10\n"
                "BNE     loc_FF82C7D8\n"
                "BL      sub_FF88D8D0\n"
                "B       loc_FF82C7BC\n"
        "loc_FF82C5F0:\n"
                "SUB     R12, R5, #0x3100\n"
                "SUBS    R12, R12, #0x11\n"
                "BEQ     loc_FF82C814\n"
                "CMP     R5, #0x3140\n"
                "BEQ     loc_FF82C878\n"
                "SUB     R12, R5, #0x3200\n"
                "SUBS    R12, R12, #1\n"
                "BEQ     loc_FF82C7D8\n"
                "SUB     R12, R5, #0x3200\n"
                "SUBS    R12, R12, #2\n"
                "BNE     loc_FF82C7D8\n"
                "B       loc_FF82C814\n"
        "loc_FF82C694:\n"
                "MOV     R4, #1\n"
                "MOV     R0, #2\n"
                "BL      sub_FF86E040\n"
                "CMP     R0, #1\n"
                "MOVEQ   R4, #2\n"
                "MOV     R0, R4\n"
                "BL      sub_FF822450\n"
                "CMP     R0, #0\n"
                "STRNE   R8, [R6,#0x14]\n"
                "BNE     loc_FF82C6F4\n"
                "BL      sub_FF874DBC\n"
                "BL      sub_FF871B90\n"
                "BL      sub_FF872718\n"
                "BL      sub_FF87145C\n"
                "BL      sub_FF872EBC\n"
                "BL      sub_FF87330C\n"
                "BL      sub_FF873790\n"
                "CMP     R0, #0\n"
                "BEQ     loc_FF82C6FC\n"
                "BL      sub_FF82C038\n"
                "BL      sub_FF8736F4\n"
                "MOV     R1, R0\n"
                "LDR     R0, =0x1167\n"
                "BL      sub_FF86B264\n"
        "loc_FF82C6F4:\n"
                "MOV     R0, R7\n"
        "locret_FF82C6F8:\n"
                "LDMFD   SP!, {R3-R11,PC}\n"
        "loc_FF82C6FC:\n"
                "BL      sub_FF8261C8\n"
                "CMP     R0, #1\n"
                "LDRNE   R0, =0x310B\n"
                "LDREQ   R0, =0x310C\n"
                "MOV     R1, #0\n"
                "BL      sub_FF86B264\n"
                "BL      sub_FF870E94_my\n"        
                "B       loc_FF82C6F4\n"
        "loc_FF82C71C:\n"
                "STR     R8, [R6,#0x10]\n"
                "LDR     R6, =0x4508\n"
                "LDR     R4, =0x1168\n"
                "CMP     R1, #0\n"
                "BEQ     loc_FF82C744\n"
                "BL      sub_FF86E808\n"
                "B       loc_FF82C750\n"
        "loc_FF82C738:\n"
                "MOV     R0, R6\n"
                "BL      sub_FF859888\n"
                "B       loc_FF82C7BC\n"
        "loc_FF82C744:\n"
                "BL      sub_FF871E38\n"
                "BL      sub_FF871D9C\n"
                "BL      sub_FF825EE8\n"
        "loc_FF82C750:\n"
                "CMP     R5, R4\n"
                "BEQ     loc_FF82C738\n"
                "B       loc_FF82C7BC\n"
        "loc_FF82C75C:\n"
                "MOV     R0, #1\n"
                "BL      sub_FF86E934\n"
                "MOV     R1, R11\n"
                "MOV     R0, R10\n"
                "B       loc_FF82C7E0\n"
        "loc_FF82C770:\n"
                "CMP     R2, #1\n"
                "BNE     loc_FF82C814\n"
                "BL      sub_FF86E808\n"
                "B       loc_FF82C7BC\n"
        "loc_FF82C780:\n"
                "MOV     R0, #2\n"
                "B       loc_FF82C78C\n"
        "loc_FF82C788:\n"
                "MOV     R0, #1\n"
        "loc_FF82C78C:\n"
                "BL      sub_FF82CDC0\n"
                "B       loc_FF82C7BC\n"
        "loc_FF82C794:\n"
                "MOV     R0, #0\n"
                "B       loc_FF82C78C\n"
        "loc_FF82C79C:\n"
                "LDR     R0, [R6,#0xC]\n"
                "SUB     R12, R0, #0x8000\n"
                "SUBS    R12, R12, #2\n"
                "BEQ     loc_FF82C7BC\n"
                "LDR     R0, =0x10A5\n"
                "BL      sub_FF86CF90\n"
                "CMP     R0, #0\n"
                "BEQ     loc_FF82C7C4\n"
        "loc_FF82C7BC:\n"
                "MOV     R0, #0\n"
                "LDMFD   SP!, {R3-R11,PC}\n"
        "loc_FF82C7C4:\n"
                "CMP     R5, R9\n"
                "STREQ   R8, [R6,#0x34]\n"
                "BEQ     loc_FF82C7D8\n"
                "CMP     R5, R10\n"
                "STREQ   R8, [R6,#0x30]\n"
        "loc_FF82C7D8:\n"
                "MOV     R1, #0\n"
        "loc_FF82C7DC:\n"
                "MOV     R0, R5\n"
        "loc_FF82C7E0:\n"
                "BL      sub_FF86FE88_my\n"        
                "LDMFD   SP!, {R3-R11,PC}\n"
        "loc_FF82C7E8:\n"
                "BL      sub_FF876EC4\n"
                "CMP     R0, #0\n"
                "BLNE    sub_FF875DA0\n"
                "B       loc_FF82C814\n"
        "loc_FF82C7F8:\n"
                "BL      sub_FF86CF90\n"
                "CMP     R0, #0\n"
                "BNE     loc_FF82C7BC\n"
        "loc_FF82C804:\n"
                "MOV     R0, R5\n"
                "BL      sub_FF82C158\n"
                "LDMFD   SP!, {R3-R11,PC}\n"
        "loc_FF82C810:\n"
                "BL      sub_FF82CD90\n"
        "loc_FF82C814:\n"
                "MOV     R1, R4\n"
                "B       loc_FF82C7DC\n"
        "loc_FF82C81C:\n"
                "MOV     R1, #0\n"
                "BL      sub_FF86FE88_my\n"        
                "MOV     R1, #0\n"
                "MOV     R0, R11\n"
                "BL      sub_FF86FE88_my\n"        
                "MOV     R1, #0\n"
                "MOV     R0, R9\n"
                "B       loc_FF82C848\n"
        "loc_FF82C83C:\n"
                "CMP     R2, #0\n"
                "BNE     loc_FF82C7BC\n"
        "loc_FF82C844:\n"
                "MOV     R1, #0\n"
        "loc_FF82C848:\n"
                "BL      sub_FF86FE88_my\n"        
                "B       loc_FF82C7BC\n"
        "loc_FF82C850:\n"
                "STR     R7, [R6,#0x20]\n"
                "BL      sub_FF82CA84\n"
                "B       loc_FF82C814\n"
        "loc_FF82C85C:\n"
                "STR     R7, [R6,#0x20]\n"
                "BL      sub_FF82CA84\n"
                "LDR     R0, [R6,#0x10]\n"
                "CMP     R0, #1\n"
                "BNE     loc_FF82C814\n"
                "BL      sub_FF86E84C\n"
                "B       loc_FF82C7BC\n"
        "loc_FF82C878:\n"
                "CMP     R1, #0\n"
                "BLEQ    sub_FF82CA84\n"
                "B       loc_FF82C7BC\n"
        "loc_FF82C884:\n"
                "MOV    R0, #0xFFFFFFFF\n"
                "B       loc_FF82C844\n"
        );
}; 

void __attribute__((naked,noinline)) sub_FF870E94_my() { 
        asm volatile (
                "STMFD   SP!, {R4,LR}\n"
                "BL      sub_FF82CA50\n"
                "MOV     R4, R0\n"
                "BL      sub_FF870FB0\n"
                "MOV     R0, R4\n"
                "BL      sub_FF870D44\n"
                "BL      sub_FF82CA50\n"
                "MOV     R4, R0\n"
                "LDR     R0, =0x5E24\n"
                "LDR     R0, [R0]\n"
                "TST     R0, #1\n"
                "BEQ     loc_FF870ED0\n"
        "loc_FF870EC4:\n"
                "MOV     R1, R4\n"
                "MOV     R0, #2\n"
                "B       loc_FF870F38\n"
        "loc_FF870ED0:\n"
                "TST     R0, #0x2000\n"
                "BEQ     loc_FF870EEC\n"
                "TST     R0, #0x200\n"
                "LDREQ   R1, =0x4004\n"
                "LDRNE   R1, =0x8002\n"
                "MOV     R0, #3\n"
                "B       loc_FF870F38\n"
        "loc_FF870EEC:\n"
                "TST     R0, #0x10\n"
                "BNE     loc_FF870EC4\n"
                "TST     R0, #0x40\n"
                "BEQ     loc_FF870F08\n"
        "loc_FF870EFC:\n"
                "MOV     R1, R4\n"
                "MOV     R0, #1\n"
                "B       loc_FF870F38\n"
        "loc_FF870F08:\n"
                "TST     R0, #0x20\n"
                "BEQ     loc_FF870F24\n"
                "TST     R0, #0x4000\n"
                "BNE     loc_FF870F24\n"
        "loc_FF870F18:\n"
                "MOV     R1, R4\n"
                "MOV     R0, #0\n"
                "B       loc_FF870F38\n"
        "loc_FF870F24:\n"
                "LDR     R1, =0x102\n"
                "BICS    R1, R1, R0\n"
                "BNE     loc_FF870F40\n"
                "MOV     R1, R4\n"
                "MOV     R0, #6\n"
        "loc_FF870F38:\n"
                "LDMFD   SP!, {R4,LR}\n"
                "B       sub_FF870CE0_my\n"  
        "loc_FF870F40:\n"
                "TST     R0, #0x100\n"
                "BNE     loc_FF870EC4\n"
                "TST     R0, #0x4000\n"
                "TSTEQ   R0, #0x400\n"
                "BNE     loc_FF870EFC\n"
                "TST     R0, #0x200\n"
                "TSTEQ   R0, #2\n"
                "BNE     loc_FF870F18\n"
                "TST     R0, #0x40000\n"
                "BEQ     loc_FF870EC4\n"
                "TST     R0, #0x200000\n"
                "MOVEQ   R1, R4\n"
                "MOVEQ   R0, #1\n"
                "BLEQ    sub_FF870CE0_my\n"  
                "B       loc_FF870EC4\n"
        );
}; 

void __attribute__((naked,noinline)) sub_FF870CE0_my() { 
        asm volatile (
                "STMFD   SP!, {R4-R6,LR}\n"
                "MOVS    R4, R0\n"
                "MOV     R0, #1\n"
                "MOV     R5, R1\n"
                "BNE     loc_FF870D20\n"
                "MOV     R1, #0\n"
                "MOV     R0, #0\n"
                "BL      sub_FF86DFD0\n"
                "BL      sub_FF82CA50\n"
                "SUB     R12, R0, #0x1000\n"
                "SUBS    R12, R12, #0x5B\n"
                "BNE     loc_FF870D18\n"
        "loc_FF870D10:\n"
                "BL      sub_FF870C28\n"
                "B       loc_FF870D28\n"
        "loc_FF870D18:\n"
                "BL      sub_FF870C68\n"
                "B       loc_FF870D28\n"
        "loc_FF870D20:\n"
                "CMP     R4, #5\n"
                "BEQ     loc_FF870D10\n"
        "loc_FF870D28:\n"
                "CMP     R0, #0\n"
                "LDREQ   R5, =0x1162\n"
                "MOVEQ   R4, #2\n"
                "MOV     R0, R4\n"
                "MOV     R1, R5\n"
                "LDMFD   SP!, {R4-R6,LR}\n"
                "B       sub_FF86FE88_my\n"  
        );
}; 

void __attribute__((naked,noinline)) sub_FF86FE88_my() { 
        asm volatile (
                "STMFD   SP!, {R4-R8,LR}\n"
                "MOV     R8, R1\n"
                "MOV     R4, R0\n"
                "BL      sub_FF873790\n"
                "CMP     R0, #0\n"
                "BNE     loc_FF870180\n"
                "MOV     R1, R8\n"
                "MOV     R0, R4\n"
                "BL      sub_FF86EAF0\n"
                "LDR     R5, =0x5D58\n"
                "MOV     R7, #1\n"
                "LDR     R0, [R5,#0x10]\n"
                "MOV     R6, #0\n"
                "CMP     R0, #0x16\n"
                "ADDLS   PC, PC, R0,LSL#2\n"
                "B       loc_FF870180\n"
        "loc_FF86FEC8:\n"
                "B       loc_FF86FF24\n"
        "loc_FF86FECC:\n"
                "B       loc_FF86FF4C\n"
        "loc_FF86FED0:\n"
                "B       loc_FF86FF90\n"
        "loc_FF86FED4:\n"
                "B       loc_FF870050\n"
        "loc_FF86FED8:\n"
                "B       loc_FF870060\n"
        "loc_FF86FEDC:\n"
                "B       loc_FF870180\n"
        "loc_FF86FEE0:\n"
                "B       loc_FF870180\n"
        "loc_FF86FEE4:\n"
                "B       loc_FF8700DC\n"
        "loc_FF86FEE8:\n"
                "B       loc_FF86FF34\n"
        "loc_FF86FEEC:\n"
                "B       loc_FF86FF40\n"
        "loc_FF86FEF0:\n"
                "B       loc_FF8700DC\n"
        "loc_FF86FEF4:\n"
                "B       loc_FF86FF84\n"
        "loc_FF86FEF8:\n"
                "B       loc_FF870180\n"
        "loc_FF86FEFC:\n"
                "B       loc_FF870180\n"
        "loc_FF86FF00:\n"
                "B       loc_FF86FF9C\n"
        "loc_FF86FF04:\n"
                "B       loc_FF86FFE4\n"
        "loc_FF86FF08:\n"
                "B       loc_FF87001C\n"
        "loc_FF86FF0C:\n"
                "B       loc_FF86FF58\n"
        "loc_FF86FF10:\n"
                "B       loc_FF870168\n"
        "loc_FF86FF14:\n"
                "B       loc_FF8700E8\n"
        "loc_FF86FF18:\n"
                "B       loc_FF870118\n"
        "loc_FF86FF1C:\n"
                "B       loc_FF870118\n"
        "loc_FF86FF20:\n"
                "B       loc_FF87006C\n"
        "loc_FF86FF24:\n"
                "MOV     R1, R8\n"
                "MOV     R0, R4\n"
                "LDMFD   SP!, {R4-R8,LR}\n"
                "B       sub_FF86F5AC_my\n"    
        "loc_FF86FF34:\n"
                "MOV     R0, R4\n"
                "LDMFD   SP!, {R4-R8,LR}\n"
                "B       sub_FF8708D8\n"
        "loc_FF86FF40:\n"
                "MOV     R0, R4\n"
                "LDMFD   SP!, {R4-R8,LR}\n"
                "B       sub_FF86FA78\n"
        "loc_FF86FF4C:\n"
                "MOV     R0, R4\n"
                "LDMFD   SP!, {R4-R8,LR}\n"
                "B       sub_FF86F194\n"
        "loc_FF86FF58:\n"
                "SUB     R12, R4, #0x1000\n"
                "SUBS    R12, R12, #0xA5\n"
                "STREQ   R7, [R5,#0x88]\n"
                "BEQ     loc_FF870178\n"
                "SUB     R12, R4, #0x3000\n"
                "SUBS    R12, R12, #6\n"
                "BNE     loc_FF870180\n"
                "MOV     R0, #0\n"
                "BL      sub_FF82BED0\n"
                "BL      sub_FF8707B8\n"
                "B       loc_FF870178\n"
        "loc_FF86FF84:\n"
                "MOV     R0, R4\n"
                "LDMFD   SP!, {R4-R8,LR}\n"
                "B       sub_FF8707F0\n"
        "loc_FF86FF90:\n"
                "MOV     R0, R4\n"
                "LDMFD   SP!, {R4-R8,LR}\n"
                "B       sub_FF86F36C\n"
        "loc_FF86FF9C:\n"
                "MOV     R0, R4\n"
                "LDMFD   SP!, {R4-R8,LR}\n"
                "B       sub_FF86FC24\n"
        "loc_FF86FFE4:\n"
                "SUB     R12, R4, #0x3200\n"
                "SUBS    R12, R12, #2\n"
                "BNE     loc_FF870180\n"
                "MOV     R0, #3\n"
                "BL      sub_FF86E9D4\n"
                "MOV     R0, #8\n"
                "BL      sub_FF82BE2C\n"
                "MOV     R1, #0\n"
                "MOV     R0, #0x19\n"
                "BL      sub_FF83A1F4\n"
                "BL      sub_FF871E38\n"
                "BL      sub_FF8720D0\n"
                "BL      sub_FF8714CC\n"
                "B       loc_FF870178\n"
        "loc_FF87001C:\n"
                "SUB     R12, R4, #0x3300\n"
                "SUBS    R12, R12, #1\n"
                "BNE     loc_FF870180\n"
                "LDR     R0, =0x4010\n"
                "STR     R6, [R5,#0x80]\n"
                "BL      sub_FF82BE2C\n"
                "BL      sub_FF98E678\n"
                "BL      sub_FF8714CC\n"
                "MOV     R0, #4\n"
                "BL      sub_FF86E9D4\n"
                "MOV     R0, #1\n"
                "BL      sub_FF872F90\n"
                "B       loc_FF870178\n"
        "loc_FF870050:\n"
                "MOV     R1, R8\n"
                "MOV     R0, R4\n"
                "LDMFD   SP!, {R4-R8,LR}\n"
                "B       sub_FF86FD80\n"
        "loc_FF870060:\n"
                "MOV     R0, R4\n"
                "LDMFD   SP!, {R4-R8,LR}\n"
                "B       sub_FF870A1C\n"
        "loc_FF87006C:\n"
                "LDR     R8, =0x1182\n"
                "CMP     R4, R8\n"
                "STREQ   R7, [R5,#0xB8]\n"
                "BEQ     loc_FF870178\n"
                "SUB     R12, R4, #0x1000\n"
                "SUBS    R12, R12, #0x1AC\n"
                "BEQ     loc_FF8700C4\n"
                "SUB     R12, R4, #0x3000\n"
                "SUBS    R12, R12, #0x224\n"
                "BNE     loc_FF870180\n"
                "MOV     R0, #8\n"
                "BL      sub_FF82BE2C\n"
                "MOV     R0, #3\n"
                "BL      sub_FF86E9D4\n"
                "STR     R6, [R5,#0xBC]\n"
                "LDR     R0, [R5,#0xB8]\n"
                "CMP     R0, #0\n"
                "MOVNE   R1, #0\n"
                "MOVNE   R0, R8\n"
                "STRNE   R6, [R5,#0xB8]\n"
                "BLNE    sub_FF86FD80\n"
                "B       loc_FF870178\n"
        "loc_FF8700C4:\n"
                "LDR     R0, [R5,#0xBC]\n"
                "CMP     R0, #0\n"
                "BNE     loc_FF870178\n"
                "BL      sub_FF98C758\n"
                "STR     R7, [R5,#0xBC]\n"
                "B       loc_FF870178\n"
        "loc_FF8700DC:\n"
                "MOV     R0, R4\n"
                "LDMFD   SP!, {R4-R8,LR}\n"
                "B       sub_FF86F970_my\n"  

        "loc_FF8700E8:\n"
                "LDR     R12, =0x10B0\n"
                "CMP     R4, R12\n"
                "BEQ     loc_FF870114\n"
                "BGT     loc_FF870120\n"
                "CMP     R4, #4\n"
                "BEQ     loc_FF870148\n"
                "SUB     R12, R4, #0x1000\n"
                "SUBS    R12, R12, #0xAA\n"
                "SUBNE   R12, R4, #0x1000\n"
                "SUBNES  R12, R12, #0xAE\n"
                "BNE     loc_FF870180\n"
        "loc_FF870114:\n"
                "BL      sub_FF86E6D8\n"
        "loc_FF870118:\n"
                "MOV     R0, R6\n"
                "LDMFD   SP!, {R4-R8,PC}\n"
        "loc_FF870120:\n"
                "SUB     R12, R4, #0x2000\n"
                "SUBS    R12, R12, #4\n"
                "BEQ     loc_FF870160\n"
                "SUB     R12, R4, #0x5000\n"
                "SUBS    R12, R12, #1\n"
                "SUBNE   R12, R4, #0x5000\n"
                "SUBNES  R12, R12, #6\n"
                "BNE     loc_FF870180\n"
                "BL      sub_FF86F134\n"
                "B       loc_FF870178\n"
        "loc_FF870148:\n"
                "LDR     R0, [R5,#0x2C]\n"
                "CMP     R0, #0\n"
                "BNE     loc_FF870160\n"
                "BL      sub_FF870360\n"
                "BL      sub_FF825EA0\n"
                "B       loc_FF870178\n"
        "loc_FF870160:\n"
                "BL      sub_FF86E714\n"
                "B       loc_FF870178\n"
        "loc_FF870168:\n"
                "SUB     R12, R4, #0x3000\n"
                "SUBS    R12, R12, #0x130\n"
                "BNE     loc_FF870180\n"
                "BL      sub_FF86E7D4\n"
        "loc_FF870178:\n"
                "MOV     R0, #0\n"
                "LDMFD   SP!, {R4-R8,PC}\n"
        "loc_FF870180:\n"
                "MOV     R0, #1\n"
                "LDMFD   SP!, {R4-R8,PC}\n"
        );
}; 

void __attribute__((naked,noinline)) sub_FF86F5AC_my() { 
        asm volatile (
                "STMFD   SP!, {R4-R8,LR}\n"
                "LDR     R7, =0x8002\n"
                "LDR     R4, =0x5D58\n"
                "CMP     R0, #3\n"
                "MOV     R6, R1\n"
                "MOV     R5, #1\n"
                "BEQ     loc_FF86F720\n"
                "BGT     loc_FF86F5E8\n"
                "CMP     R0, #0\n"
                "BEQ     loc_FF86F62C\n"
                "CMP     R0, #1\n"
                "BEQ     loc_FF86F6B0\n"
                "CMP     R0, #2\n"
                "BNE     loc_FF86F7A8\n"
                "B       loc_FF86F600\n"
        "loc_FF86F5E8:\n"
                "CMP     R0, #6\n"
                "STREQ   R5, [R4,#0x28]\n"
                "BEQ     loc_FF86F718\n"
                "SUB     R12, R0, #0x2000\n"
                "SUBS    R12, R12, #4\n"
                "BNE     loc_FF86F7A8\n"
        "loc_FF86F600:\n"
                "SUB     R12, R6, #0x1100\n"
                "SUBS    R12, R12, #0x62\n"
                "BNE     loc_FF86F61C\n"
                "MOV     R1, R7\n"
                "MOV     R0, #0\n"
                "BL      sub_FF87278C\n"
                "STR     R5, [R4,#0x60]\n"
        "loc_FF86F61C:\n"
                "BL      sub_FF871E38\n"
                "BL      sub_FF8720D0\n"
                "BL      sub_FF86F098\n"
                "B       loc_FF86F7A0\n"
        "loc_FF86F62C:\n"
                "MOV     R0, #7\n"
                "BL      sub_FF86E9D4\n"
                "MOV     R0, R7\n"
                "BL      sub_FF82BE2C\n"
                "BL      sub_FF8710FC\n"
                "BL      sub_FF871C90\n"
                "MOV     R1, R7\n"
                "MOV     R0, #0\n"
                "BL      sub_FF87278C\n"
                "LDR     R1, =0xFF86F7E0\n"
                "MOV     R0, #0x20\n"
                "STR     R6, [R4,#0x18]\n"
                "BL      sub_FF867A8C\n"
                "LDR     R1, =0xFF86F7EC\n"
                "MOV     R0, #0x20\n"
                "BL      sub_FF867A8C\n"
                "STR     R5, [R4,#0x28]\n"
                "BL      sub_FF82BFA4\n"
                "BL      sub_FF82BEF8\n"
                "LDR     R0, [R4,#0x1C]\n"
                "LDR     R1, [R4,#0x20]\n"
                "ORRS    R0, R0, R1\n"
                "BLNE    sub_FF87033C\n"
                "LDR     R0, [R4,#0x68]\n"
                "CMP     R0, #0\n"
                "BNE     loc_FF86F69C\n"
                "BL      sub_FF82C014\n"
                "B       loc_FF86F6A4\n"
        "loc_FF86F69C:\n"
                "BL      sub_FF825C30\n"
                "BL      sub_FF82C9E8\n"
        "loc_FF86F6A4:\n"
                "BL      sub_FF8710C0_my\n"  
                "BL      sub_FF871138\n"
                "B       loc_FF86F7A0\n"
        "loc_FF86F6B0:\n"
                "MOV     R0, #8\n"
                "BL      sub_FF86E9D4\n"
                "BL      sub_FF8710FC\n"
                "BL      sub_FF871C90\n"
                "LDR     R5, =0x4004\n"
                "MOV     R0, #0\n"
                "MOV     R1, R5\n"
                "BL      sub_FF87278C\n"
                "LDR     R1, =0xFF86F7FC\n"
                "MOV     R0, #0x20\n"
                "BL      sub_FF867A8C\n"
                "BL      sub_FF8710C0_my\n"  
                "BL      sub_FF8711CC\n"
                "BL      sub_FF82C9AC\n"
                "MOV     R0, R5\n"
                "BL      sub_FF82BE2C\n"
                "LDR     R0, [R4,#0x68]\n"
                "CMP     R0, #0\n"
                "BNE     loc_FF86F704\n"
                "BL      sub_FF82C014\n"
                "B       loc_FF86F708\n"
        "loc_FF86F704:\n"
                "BL      sub_FF825C30\n"
        "loc_FF86F708:\n"
                "BL      sub_FF871168\n"
                "LDR     R0, [R4,#0x30]\n"
                "CMP     R0, #0\n"
                "BEQ     loc_FF86F7A0\n"
        "loc_FF86F718:\n"
                "BL      sub_FF870384\n"
                "B       loc_FF86F7A0\n"
        "loc_FF86F720:\n"
                "MOV     R1, R6\n"
                "MOV     R0, #0\n"
                "BL      sub_FF87278C\n"
                "LDR     R1, =0xFF86F808\n"
                "MOV     R0, #0x20\n"
                "BL      sub_FF867A8C\n"
                "STR     R5, [R4,#0x68]\n"
                "BL      sub_FF8711CC\n"
                "BL      sub_FF82C9AC\n"
                "BL      sub_FF870318\n"
                "BL      sub_FF82CA44\n"
                "CMP     R0, #0\n"
                "LDRNE   R0, =0x804B\n"
                "MOVNE   R1, #0\n"
                "BLNE    sub_FF86DE84\n"
                "BL      sub_FF87260C\n"
                "MOV     R0, #0x80\n"
                "BL      sub_FF82BE2C\n"
                "BL      sub_FF872018\n"
                "BL      sub_FF88FBCC\n"
                "BL      sub_FF9470BC\n"
                "BL      sub_FF991504\n"
                "BL      sub_FF8719B8\n"
                "BL      sub_FF871E70\n"
                "MOV     R0, #9\n"
                "BL      sub_FF86E9D4\n"
                "LDR     R0, =0x300E\n"
                "MOV     R1, R6\n"
                "BL      sub_FF86B264\n"
                "MOV     R1, #0\n"
                "MOV     R0, #1\n"
                "BL      sub_FF87278C\n"
        "loc_FF86F7A0:\n"
                "MOV     R0, #0\n"
                "LDMFD   SP!, {R4-R8,PC}\n"
        "loc_FF86F7A8:\n"
                "MOV     R0, #1\n"
                "LDMFD   SP!, {R4-R8,PC}\n"
        );
}; 

void __attribute__((naked,noinline)) sub_FF8710C0_my() { 
        asm volatile (
                "LDR     R0, =0x5E30\n"
                "STMFD   SP!, {R3,LR}\n"
                "LDR     R1, [R0,#4]\n"
                "CMP     R1, #0\n"
                "BNE     locret_FF8710F8\n"
                "MOV     R1, #1\n"
                "STR     R1, [R0,#4]\n"
                "MOV     R3, #0\n"
                "STR     R3, [SP]\n"

                "LDR     R3, =task_InitFileModules_my\n"  
                "MOV     R1, #0x19\n"
                "LDR     R0, =0xFF871224\n"
                "MOV     R2, #0x1000\n"
                "BL      sub_FF81BAF0\n"
        "locret_FF8710F8:\n"
                "LDMFD   SP!, {R12,PC}\n"
        );
}; 

void __attribute__((naked,noinline)) task_InitFileModules_my() { 
        asm volatile (
                "STMFD   SP!, {R4-R6,LR}\n"
                "BL      sub_FF86A084\n"
                "LDR     R5, =0x5006\n"
                "MOVS    R4, R0\n"
                "MOVNE   R1, #0\n"
                "MOVNE   R0, R5\n"
                "BLNE    sub_FF86B264\n"
                "BL      sub_FF86A0B0_my\n"  

 

                "CMP     R4, #0\n"
                "MOVEQ   R0, R5\n"
                "LDMEQFD SP!, {R4-R6,LR}\n"
                "MOVEQ   R1, #0\n"
                "BEQ     sub_FF86B264\n"
                "LDMFD   SP!, {R4-R6,PC}\n"
        );
}; 

void __attribute__((naked,noinline)) sub_FF86A0B0_my() { 
        asm volatile (
                "STMFD   SP!, {R4,LR}\n"
                "BL      sub_FF84D658_my\n"  
                "LDR     R4, =0x58B0\n"
                "LDR     R0, [R4,#4]\n"
                "CMP     R0, #0\n"
                "BNE     loc_FF86A0E0\n"
                "BL      sub_FF87A208\n"
                "BL      sub_FF8FDA18\n"
                "BL      sub_FF87A208\n"
                "BL      sub_FF90A56C\n"
                "BL      sub_FF87A218\n"
                "BL      sub_FF8FDAC0\n"
        "loc_FF86A0E0:\n"
                "MOV     R0, #1\n"
                "STR     R0, [R4]\n"
                "LDMFD   SP!, {R4,PC}\n"
        );
}; 

void __attribute__((naked,noinline)) sub_FF84D658_my() { 
        asm volatile (
                "STMFD   SP!, {R4-R6,LR}\n"
                "MOV     R6, #0\n"
                "MOV     R0, R6\n"
                "BL      sub_FF84D228\n"
                "LDR     R4, =0x15F80\n"
                "MOV     R5, #0\n"
                "LDR     R0, [R4,#0x38]\n"
                "BL      sub_FF84DBF0\n"
                "CMP     R0, #0\n"
                "LDREQ   R0, =0x2B44\n"
                "STREQ   R5, [R0,#0xC]\n"
                "STREQ   R5, [R0,#0x10]\n"
                "STREQ   R5, [R0,#0x14]\n"
                "MOV     R0, R6\n"
                "BL      sub_FF84D268\n"
                "MOV     R0, R6\n"
                "BL      sub_FF84D494_my\n"  
                "MOV     R5, R0\n"
                "MOV     R0, R6\n"
                "BL      sub_FF84D500\n"
                "LDR     R1, [R4,#0x3C]\n"
                "AND     R2, R5, R0\n"
                "CMP     R1, #0\n"
                "MOV     R0, #0\n"
                "MOVEQ   R0, #0x80000001\n"
                "BEQ     loc_FF84D6EC\n"
                "LDR     R3, [R4,#0x2C]\n"
                "CMP     R3, #2\n"
                "MOVEQ   R0, #4\n"
                "CMP     R1, #5\n"
                "ORRNE   R0, R0, #1\n"
                "BICEQ   R0, R0, #1\n"
                "CMP     R2, #0\n"
                "BICEQ   R0, R0, #2\n"
                "ORREQ   R0, R0, #0x80000000\n"
                "BICNE   R0, R0, #0x80000000\n"
                "ORRNE   R0, R0, #2\n"
        "loc_FF84D6EC:\n"
                "STR     R0, [R4,#0x40]\n"
                "LDMFD   SP!, {R4-R6,PC}\n"
        );
}; 

void __attribute__((naked,noinline)) sub_FF84D494_my() { 
        asm volatile (
                "STMFD   SP!, {R4-R6,LR}\n"
                "LDR     R5, =0x2B44\n"
                "MOV     R6, R0\n"
                "LDR     R0, [R5,#0x10]\n"
                "CMP     R0, #0\n"
                "MOVNE   R0, #1\n"
                "LDMNEFD SP!, {R4-R6,PC}\n"
                "MOV     R0, #0x17\n"
                "MUL     R1, R0, R6\n"
                "LDR     R0, =0x15F80\n"
                "ADD     R4, R0, R1,LSL#2\n"
                "LDR     R0, [R4,#0x38]\n"
                "MOV     R1, R6\n"
                "BL      sub_FF84D32C_my\n"  
                "CMP     R0, #0\n"
                "LDMEQFD SP!, {R4-R6,PC}\n"
                "LDR     R0, [R4,#0x38]\n"
                "MOV     R1, R6\n"
                "BL      sub_FF84DD08\n"
                "CMP     R0, #0\n"
                "LDMEQFD SP!, {R4-R6,PC}\n"
                "MOV     R0, R6\n"
                "BL      sub_FF84CE48\n"
                "CMP     R0, #0\n"
                "MOVNE   R1, #1\n"
                "STRNE   R1, [R5,#0x10]\n"
                "LDMFD   SP!, {R4-R6,PC}\n"
        );
}; 

void __attribute__((naked,noinline)) sub_FF84D32C_my() { 
        asm volatile (
                "STMFD   SP!, {R4-R8,LR}\n"
                "MOV     R8, R0\n"
                "MOV     R0, #0x17\n"
                "MUL     R1, R0, R1\n"
                "LDR     R0, =0x15F80\n"
                "MOV     R6, #0\n"
                "ADD     R7, R0, R1,LSL#2\n"
                "LDR     R0, [R7,#0x3C]\n"
                "MOV     R5, #0\n"
                "CMP     R0, #6\n"
                "ADDLS   PC, PC, R0,LSL#2\n"
                "B       loc_FF84D478\n"
        "loc_FF84D35C:\n"
                "B       loc_FF84D390\n"
        "loc_FF84D360:\n"
                "B       loc_FF84D378\n"
        "loc_FF84D364:\n"
                "B       loc_FF84D378\n"
        "loc_FF84D368:\n"
                "B       loc_FF84D378\n"
        "loc_FF84D36C:\n"
                "B       loc_FF84D378\n"
        "loc_FF84D370:\n"
                "B       loc_FF84D470\n"
        "loc_FF84D374:\n"
                "B       loc_FF84D378\n"
        "loc_FF84D378:\n"
                "MOV     R2, #0\n"
                "MOV     R1, #0x200\n"
                "MOV     R0, #3\n"
                "BL      sub_FF86655C\n"
                "MOVS    R4, R0\n"
                "BNE     loc_FF84D398\n"
        "loc_FF84D390:\n"
                "MOV     R0, #0\n"
                "LDMFD   SP!, {R4-R8,PC}\n"
        "loc_FF84D398:\n"
                "LDR     R12, [R7,#0x4C]\n"
                "MOV     R3, R4\n"
                "MOV     R2, #1\n"
                "MOV     R1, #0\n"
                "MOV     R0, R8\n"

                
                "MOV     LR, PC\n"      
                "MOV     PC, R12\n"     

                "CMP     R0, #1\n"
                "BNE     loc_FF84D3C4\n"
                "MOV     R0, #3\n"
                "BL      sub_FF86669C\n"
                "B       loc_FF84D390\n"
        "loc_FF84D3C4:\n"
                "MOV     R0, R8\n"
                "BL      sub_FF91AD24\n"

                
                
                
                
                
                "MOV     R12, R4\n"                    
                "MOV     LR, R4\n"                     
                "MOV     R1, #1\n"                     
                "B       dg_sd_fat32_enter\n"          
           "dg_sd_fat32:\n"
                "CMP     R1, #4\n"                     
                "BEQ     dg_sd_fat32_end\n"            
                "ADD     R12, R12, #0x10\n"            
                "ADD     R1, R1, #1\n"                 
           "dg_sd_fat32_enter:\n"
                "LDRB    R2, [R12, #0x1BE]\n"          
                "LDRB    R3, [R12, #0x1C2]\n"          
                "CMP     R3, #0xB\n"                   
                "CMPNE   R3, #0xC\n"                   
                "BNE     dg_sd_fat32\n"                
                "CMP     R2, #0x00\n"                  
                "CMPNE   R2, #0x80\n"
                "BNE     dg_sd_fat32\n"                
                                                       
                "MOV     R4, R12\n"                    
                
           "dg_sd_fat32_end:\n"

                "LDRB    R1, [R4,#0x1C9]\n"
                "LDRB    R3, [R4,#0x1C8]\n"
                "LDRB    R12, [R4,#0x1CC]\n"
                "MOV     R1, R1,LSL#24\n"
                "ORR     R1, R1, R3,LSL#16\n"
                "LDRB    R3, [R4,#0x1C7]\n"
                "LDRB    R2, [R4,#0x1BE]\n"
               
                "ORR     R1, R1, R3,LSL#8\n"
                "LDRB    R3, [R4,#0x1C6]\n"
                "CMP     R2, #0\n"
                "CMPNE   R2, #0x80\n"
                "ORR     R1, R1, R3\n"
                "LDRB    R3, [R4,#0x1CD]\n"
                "MOV     R3, R3,LSL#24\n"
                "ORR     R3, R3, R12,LSL#16\n"
                "LDRB    R12, [R4,#0x1CB]\n"
                "ORR     R3, R3, R12,LSL#8\n"
                "LDRB    R12, [R4,#0x1CA]\n"
                "ORR     R3, R3, R12\n"
               

                "LDRB    R12, [LR,#0x1FE]\n"            
                "LDRB    LR, [LR,#0x1FF]\n"             


                "MOV     R4, #0\n"
                "BNE     loc_FF84D44C\n"
                "CMP     R0, R1\n"
                "BCC     loc_FF84D44C\n"
                "ADD     R2, R1, R3\n"
                "CMP     R2, R0\n"
                "CMPLS   R12, #0x55\n"
                "CMPEQ   LR, #0xAA\n"
                "MOVEQ   R6, R1\n"
                "MOVEQ   R5, R3\n"
                "MOVEQ   R4, #1\n"
        "loc_FF84D44C:\n"
                "MOV     R0, #3\n"
                "BL      sub_FF86669C\n"
                "CMP     R4, #0\n"
                "BNE     loc_FF84D484\n"
                "MOV     R6, #0\n"
                "MOV     R0, R8\n"
                "BL      sub_FF91AD24\n"
                "MOV     R5, R0\n"
                "B       loc_FF84D484\n"
        "loc_FF84D470:\n"
                "MOV     R5, #0x40\n"
                "B       loc_FF84D484\n"
        "loc_FF84D478:\n"
                "LDR     R1, =0x365\n"
                "LDR     R0, =0xFF84D320\n"
                "BL      sub_FF81BFC8\n"
        "loc_FF84D484:\n"
                "STR     R6, [R7,#0x44]!\n"
                "MOV     R0, #1\n"
                "STR     R5, [R7,#4]\n"
                "LDMFD   SP!, {R4-R8,PC}\n"
        );
}; 


void __attribute__((naked,noinline)) sub_FF86F970_my(){
asm volatile(
                 "LDR     R12, =0x201E\n"
                 "STMFD   SP!, {R4,LR}\n"
                 "CMP     R0, R12\n"
                 "BEQ     loc_FF86FA30\n"
                 "BGT     loc_FF86F9CC\n"
                 "LDR     R12, =0x2004\n"
                 "CMP     R0, R12\n"
                 "BEQ     loc_FF86FA38\n"
                 "BGT     loc_FF86F9B4\n"
                 "SUB     R12, R0, #0x1000\n"
                 "SUBS    R12, R12, #0xA9\n"
                 "SUBNE   R12, R0, #0x1000\n"
                 "SUBNES  R12, R12, #0xAD\n"
                 "SUBNE   R12, R0, #0x1000\n"
                 "SUBNES  R12, R12, #0xAF\n"
                 "BNE     loc_FF86FA48\n"
                 "B       loc_FF86FA30\n"
 "loc_FF86F9B4:\n"
                 "SUB     R12, R0, #0x2000\n"
                 "SUBS    R12, R12, #5\n"
                 "SUBNE   R12, R0, #0x2000\n"
                 "SUBNES  R12, R12, #0x1D\n"
                 "BNE     loc_FF86FA48\n"
                 "B       loc_FF86FA30\n"
 "loc_FF86F9CC:\n"
        
                 "LDR     R12, =0x5004\n"
                 "CMP     R0, R12\n"
                 "BEQ     loc_FF86FA30\n"
                 "BGT     loc_FF86F9F8\n"
                 "SUB     R12, R0, #0x3000\n"
                 "SUBS    R12, R12, #0xA\n"
                 "BEQ     loc_FF86FA2C\n"
                 "SUB     R12, R0, #0x5000\n"
                 "SUBS    R12, R12, #1\n"
                 "BNE     loc_FF86FA48\n"
                 "B       loc_FF86FA30\n"
 "loc_FF86F9F8:\n"
                 "SUB     R12, R0, #0x5000\n"
                 "SUBS    R12, R12, #6\n"
                 "BEQ     loc_FF86FA30\n"
                 "SUB     R12, R0, #0x5000\n"
                 "SUBS    R12, R12, #7\n"
                 "BNE     loc_FF86FA48\n"
                 "BL      sub_FF82C9E8\n"
                 "LDR     R1, =0x5D58\n"
                 "LDR     R0, [R1,#0x10]\n"
                 "CMP     R0, #7\n"
                 "LDREQ   R0, [R1,#0x18]\n"
                 "BLEQ    sub_FF8704E4\n"
                 "B       loc_FF86FA40\n"
 "loc_FF86FA2C:\n"
                 "BL      sub_FF82BE18\n"
 "loc_FF86FA30:\n"
                 "LDMFD   SP!, {R4,LR}\n"
                 "B       sub_FF86F820_my\n"
 "loc_FF86FA38:\n"
                 "BL      sub_FF86E658\n"
                 "BL      sub_FF86F134\n"
 "loc_FF86FA40:\n"
                 "MOV     R0, #0\n"
                 "LDMFD   SP!, {R4,PC}\n"
 "loc_FF86FA48:\n"
                 "MOV     R0, #1\n"
                 "LDMFD   SP!, {R4,PC}\n"
 );
}

